<?php
require_once($_SERVER['DOCUMENT_ROOT'].'/defaultconf.mex');
header('Content-type: text/html; charset=utf-8');
/*
 mb_internal_encoding('UTF-8');
 mb_regex_encoding('UTF-8');
 mb_http_output('UTF-8');*/
/* Set ICONV ini settings */
ini_set('iconv.input_encoding', 'UTF-8');
ini_set('iconv.output_encoding', 'UTF-8');
ini_set('iconv.internal_encoding', 'UTF-8');

/* Set ICONV function settings */
iconv_set_encoding('input_encoding', 'UTF-8');
iconv_set_encoding('output_encoding', 'UTF-8');
iconv_set_encoding('internal_encoding', 'UTF-8');

/*memoria e tempo sem limite*/
ini_set('memory_limit',-1); //sem limite
set_time_limit(0) ;         //sem limite

MYTCONN();
if( !ini_get('safe_mode') ){
	set_time_limit(25);
}

$to = '';
$sql="
select * from
(
select email from site.contato where receberInformacao='on' group by email
union
select clientes.CLCttEmail as email
from officeschema.clientes
where length(CLCttEmail) > 9
and CLCttEmail like '%@%'
and CLCttEmail not like '%nao%'
and CLCttEmail not like '%-%'
and CLCttEmail not like '% %'
group by email
) as email group by email
;";

$GetEmail = $GLOBALS['MYT']->db_array($sql);
$Total_envio = $GetEmail[0];
echo "total de emails".$Total_envio;
$valor_final = 0.0;
for ($i=8001; $i<=9500; $i++) {
	$to .= ''.$GetEmail[$i]['email'].',';
}
$to .= 'mario.pais@moneyexpress.pt';
echo $to;
$subj = $_POST['assunto'];
$motive = $_POST['mensagem'];
$toName = 'uu8t6t';
$header='<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Newsletter</title>
</head>
<body>';
$footer='</body>
</html>';


$email_pw = sprintf(
$header.
'MoneyOne - Portugal
<br>
<hr />
'.$motive.'<br /><img src="http://www.moneyexpress.pt/imagens/newsletter/Jan2011.jpg" />'
.$footer);
$mess = "$motive \r\n ";
$AttmFiles = '';
$From = '<Newsletter@moneyexpress.pt>';
$FromName = 'Money ';
$Html = '';
$result=false;
$result=authmail2($From,$FromName,$to,$toName,$subj,$mess,$email_pw,$AttmFiles,$_sysconfMailString);
if($result){
	echo " Mensagens Enviada.";
}else{
	echo "Erro";
}